﻿using System;
using System.Collections.Generic;
using System.Data;
using DBHelper;
using SME.Food.Surperise.BLL;
using SME.Food.Surperise.Model;

namespace SME.Food.Tricon.Web.AdminJS.DishesManage
{
    public partial class DishesH : System.Web.UI.Page
    {
        public Bas_Menus_BLL MenuBll = new Bas_Menus_BLL();
        public Bas_Menus_Model MenuModel = new Bas_Menus_Model();
        public Bas_Dishes_BLL bll = new Bas_Dishes_BLL();
        public Bas_Dishes_Model model = new Bas_Dishes_Model();
        public string forwardUrl = "DishesManage/DishesList.aspx";
        protected void Page_Load(object sender, EventArgs e)
        {
            string Dishes_No = Request["Dishes_No"];
            string type = Request.QueryString["type"];
            string hid = Request.Form["hid"];
            if (type == "modify")
            {
                if (hid == "add")
                {
                    Modify(0);
                }
                if (hid == "update")
                {

                    Modify(1);
                }
            }

            else if (type == "delete")
            {
                if (bll.Delete(Dishes_No))
                {
                    Common.DwzMessage(true, true, "DishesList", "DishesList", forwardUrl);
                }
                else
                {
                    Common.DwzMessage(false, false, " ", " ", " ");

                }
            }
            else if (type == "deleteAll")
            {
                Dishes_No = Request["ids"];
                if (bll.DeleteList(Dishes_No))
                {
                    Common.DwzMessage(true, true, "DishesList", "DishesList", forwardUrl);
                }
                else
                {
                    Common.DwzMessage(false, false, " ", " ", " ");

                }
            }
            else if (type == "order")
            {
                orderMenu();

            }
        }

        public void Modify(int i)
        {
            model.Dishes_No = Request.Form["Dishes_No"];
            model.Dishes_Name = Request.Form["Dishes_Name"];
            model.Dishes_Price = Decimal.Parse(Request.Form["Dishes_Price"]);
            model.Dishes_statue = Int32.Parse(Request.Form["Dishes_statue"]);

            if (i == 0)
            {
                model.Dishes_No = DbHelperSQL.GetMaxID("Dishes_No", "Bas_Dishes").ToString();
                if (bll.Add(model) > 0)
                {

                    //Response.Write("<script> alert('操作成功！');window.location='MemberManage/MemberList.aspx';</script> ");
                    // Common.DwzMessage(true, true, "MemberList", "MemberList", "AdminJS/MemberManage/MemberList.aspx");
                    Common.DwzMessage(true, true, "DishesList", "DishesList", forwardUrl);
                }
                else
                {
                    Common.DwzMessage(false, false, " ", " ", " ");

                }
            }
            if (i == 1)
            {
                model.Dishes_No = Request.Form["Dishes_No"];

                if (bll.Update(model))
                {
                    Common.DwzMessage(true, true, "DishesList", "DishesList", forwardUrl);
                }
                else
                {
                    Common.DwzMessage(false, false, " ", " ", " ");

                }
            }




        }

        public void orderMenu()
        {
            string ids = Request["ids"];
            string sqlWhere = " and  Dishes_No in (" + ids + ")";
            DataTable  TableMenu = bll.GetList(sqlWhere).Tables[0];
            if(TableMenu.Rows.Count > 0)
            {
                foreach (DataRow dr in TableMenu.Rows)
                {
                     
                }
            
            }

        }
    }
}